/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.helpdesk.controllers;

import com.helpdesk.beans.ComplaintsFacade;
import com.helpdesk.beans.DepartmentsFacade;
import com.helpdesk.entities.Departments;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import org.primefaces.component.chart.pie.PieChart;
import org.primefaces.model.chart.PieChartModel;

/**
 *
 * @author JK
 */
@ManagedBean(name="reportController")
@SessionScoped
public class ReportController {
    private PieChartModel summaryComplaintPieChart;
    private int totalComplaints;
    @EJB
    private DepartmentsFacade departmentFacade;

    public ReportController(){
       
    }

    private void createSummaryReport() {
        int total = 0;
        //complaint by department
        summaryComplaintPieChart = new PieChartModel();
        List<Departments> departments = departmentFacade.findAll();
        
        if(departments!=null){
            for(Departments de:departments){
                int complaintListSize=de.getComplaintsList().size();
                total+=complaintListSize;
                
                summaryComplaintPieChart.set(de.getName(),complaintListSize );
            }
        }
        //total complaint
        totalComplaints = total;
        //
    }

    public PieChartModel getSummaryComplaintPieChart() {
        if(summaryComplaintPieChart==null){
             createSummaryReport();
        }
        return summaryComplaintPieChart;
    }

    public int getTotalComplaints() {
        return totalComplaints;
    }
    
}
